public class RemoveElement {

    public static int removeElement(int[] nums, int val) {
        int p1=0;
        int p2=nums.length-1;
        int res=0;
        while (p1<=p2){
            if(nums[p1]==val){
                int temp=nums[p2];
                nums[p2]=nums[p1];
                nums[p1]=temp;
                p2--;
                res++;
            }else{
                p1++;
            }
        }
        return nums.length-res;
    }

    public int removeDuplicates(int[] nums) {
       if (nums.length==0){
           return 0;
       }
       int fast=1;
       int show=1;
       while (fast<nums.length){
           if(nums[fast]!=nums[fast-1]){
               nums[show]=nums[fast];
               show++;
           }
           fast++;
       }
       return show;
    }

    public static void main(String[] args) {
        int[] nums=new int[]{1};
        System.out.println(removeElement(nums,1));
        System.out.println(nums);
    }
}
